home *** CD-ROM | disk | FTP | other *** search
- /* Ackermann benchmark */
-
- /* See Software Practice and Experience, Vol 7 pp317-329 (1977) */
-
- #include <time2.h>
- #include <stdio.h>
-
- #define TRUE 1
- #define FALSE 0
-
- int main(void)
- {
- clock_t start, end;
- int i, j, k, k1;
- int failed;
-
- start=clock(); /*gets system time*/
- k = 16;
- k1 = 1;
- failed = FALSE;
- for ( i = 1;i <= 6; i++){
- j = ackermann( 3, i);
- if ( j != k - 3 )
- failed = TRUE;
-
- printf(" NO OF CALLS: %8.0f\n", (512.0*k1 - 15.0*k + 9.0*i + 37.0) / 3.0);
-
- k1 = 4 * k1;
- k = 2 * k ;
- }; /* for */
-
- end=clock();
-
- if ( failed )
- printf(" FAIL \n");
- else
- printf(" PASS \n");
- printf("The timing for this ACKERMANN test was: %f\n", (end-start) / CLK_TCK);
- return 0 ;
-
- };
- /* end of main program */
-
- ackermann(m, n)
- int m,n;
- {
- if ( m == 0 )
- return n + 1;
- else if ( n == 0 )
- return ackermann(m - 1, 1);
- else
- return ackermann(m - 1, ackermann(m, n - 1));
- } /* ackermann */
-